package com.snail.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.snail.model.dto.cart.AddCartRequestDto;
import com.snail.model.pojo.cart.BizCart;
import com.snail.model.pojo.mall.BizProduct;
import com.snail.model.pojo.mall.BizProductSku;
import com.snail.model.vo.cart.BizProductSkuVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BizCartMapper extends BaseMapper<BizCart> {



    //添加商品到购物车的方法
//    void addToCart(AddCartRequestDto addCartRequestDto);

    //查询购物车是否存在
    @Select("select * from biz_cart where user_id=#{userId} and deleted=0")
    BizCart selectByUserId(Long userId);


    //根据id查询商品
    @Select("SELECT * FROM biz_product WHERE product_id = #{productId}")
    BizProduct selectById(Integer productId);

    @Select("SELECT * FROM biz_product_sku WHERE product_id = #{productId} and specs=#{specs}")
    BizProductSku selectByProductId(Integer productId, String specs);


    BizProductSkuVo getSkuWithSeller(Integer productId);



    //连表查询product和productsku表，获取商品名称
    @Select("SELECT p.product_name, ps.* FROM biz_product_sku ps " +
            "LEFT JOIN biz_product p ON ps.product_id = p.product_id " +
            "WHERE ps.product_id = #{productId} and ps.specs=#{specs}")
    BizProductSkuVo getSkuWithSellerAndProductName(Integer productId, String specs);
    //关联查询商品表和商品规格表
//    //更新购物车的方
//    @Update("update biz_cart set selected=#{selected},update_time=#{updateTime} where id=#{id}")
//    void updateCart(BizCart bizCart);
//    //删除购物车的方法
//    @Update("update biz_cart set deleted=1,update_time=#{updateTime} where id=#{id}")
//    void deleteCart(BizCart bizCart);
//    //查询购物车的方法
//    @Select("select * from biz_cart where user_id=#{userId} and deleted=0")
//    List<BizCart> selectCartList(BizCart bizCart);
//    //判断购物车中是否有该商品
//    @Select("select * from biz_cart where user_id=#{userId} and product_id=#{productId} and deleted=0")
//    BizCart selectCart(BizCart bizCart);

}
